package org.sdau.rotten.library.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class DispatcherPageController {
    @GetMapping("/dispatcher/{page}")
    public String getPage(@PathVariable String page) {
        return page;
    }

    @GetMapping
    public String indexPage(HttpServletRequest request) {

        if (request.getSession().getAttribute("username") != null ) {
            return "redirect:/custom/myAppoint";
        }
        else {
            return "login";
        }
    }

    @RequestMapping("/403")
    public String unauth(){
        return "403";
    }

    @RequestMapping("/404Page")
    public String error(){
        return "404";
    }

    @GetMapping("/registerPage")
    public String registerPage() {
        return "register";
    }

    @GetMapping("/loginPage")
    public String loginPage() {
        return "login";
    }

    @GetMapping("/uploadPage")
    public String upLoadPage() {
        return "upload_page";
    }
}
